<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字</title>
</head>
<body>
<h3>已生成一个1~100的随机整数：</h3>
<input type="text" id="num" placeholder="请输入数字">
<button onclick="guess()">点我验证</button>
<h3>小提示：<span class="s"></span></h3>
<script>
  var random = parseInt(Math.random()*100+1);
  var order = 0;
  console.log(random);
  function guess(){
    let i = document.getElementById('num');
    let value = parseInt(i.value);
    console.log(value);
    /*if(isNaN(value)){
      alert('请输入数字');
      return;
    }*/
    if(!/^\d+$/.test(value)){
      alert('请输入数字');
      return;
    }
    let span = document.querySelector('.s');
    //order++;//也可写在这里，猜一次order+1
    if(value>random){
      span.innerHTML='猜大了';
      order++;
    }else if(value===random){
      order++;
      span.innerHTML='恭喜你用了'+order+'次就猜对了'
    }else{
      span.innerHTML='猜小了';
      order++;
    }

  }

</script>
</body>

</html>